<template>
  <van-popup
    v-model="visible"
    :overlay="false"
    :close-on-click-overlay="false"
    class="m-topnav"
    position="top"
    round
    close-on-popstate
  >
    <div class="m-topnav-title">
      <span class="m-title">{{ titles }}</span>
      <van-icon name="cross" class="m-close" @click="visible = false" />
    </div>
    <slot v-if="$slots.default"></slot>
    <ul v-else class="m-menu-link">
      <li>
        <img
          src="https://files.cnhnb.com/indexIcon/huinongIcon.png"
          class="m-menu-link-img"
          alt="惠农网"
        /><a
          href="https://www.cnhnb.com/"
          target="_blank"
          rel="noopener noreferrer"
          >惠农网</a
        >
      </li>
      <li>
        <img
          src="https://files.cnhnb.com/indexIcon/houseIcon.png"
          class="m-menu-link-img"
          alt="招商通"
        />
        <a href="/m" target="_blank" rel="noopener noreferrer">招商通</a>
      </li>
      <li>
        <img
          src="https://files.cnhnb.com/indexIcon/buildingIcon.png"
          class="m-menu-link-img"
          alt="找企业"
        /><a href="/mqiye" target="_blank" rel="noopener noreferrer">找企业</a>
      </li>
      <li>
        <img
          src="https://files.cnhnb.com/indexIcon/miniCare.png"
          class="m-menu-link-img"
          alt="找产品"
        /><a href="/mchanpin" target="_blank" rel="noopener noreferrer"
          >找产品</a
        >
      </li>
      <li>
        <img
          src="https://files.cnhnb.com/indexIcon/merchantIcon.png"
          class="m-menu-link-img"
          alt="经销商库"
        /><a href="/mjingxiaoshang" target="_blank" rel="noopener noreferrer"
          >经销商库</a
        >
      </li>
      <li>
        <img
          src="https://files.cnhnb.com/indexIcon/serviceIcon.png"
          class="m-menu-link-img"
          alt="经销商库"
        /><a
          href="https://m.cnhnb.com/html/im/#/home"
          target="_blank"
          rel="noopener noreferrer"
          >联系客服</a
        >
      </li>
    </ul>
  </van-popup>
</template>
<script>
export default {
  name: 'MTopnav',
  props: {
    value: {
      type: Boolean,
    },
    title: {
      type: String,
    },
    links: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      titles: '功能直达',
    }
  },
  computed: {
    visible: {
      get() {
        return this.value
      },
      set(val) {
        this.$emit('input', val)
      },
    },
  },
}
</script>
<style lang="less" scoped>
ul,
li {
  margin: 0;
  padding: 0;
}
.m-topnav {
  padding: 20px 16px;
  background: rgba(17, 80, 51, 0.92);
  &-title {
    height: 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .m-title,
    .m-close {
      color: #fff;
      font-size: 16px;
    }
    .m-close {
      font-size: 20px;
      font-weight: 600;
    }
  }
  .m-menu-link {
    &-img {
      width: 26px;
      height: 26px;
    }
    li {
      width: 83px;
      height: 83px;
      background-color: rgba(0, 0, 0, 0.3);
      border-radius: 5px;
      margin-right: 12px;
      margin-top: 16px;
      display: inline-flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      vertical-align: top;
      i {
        display: flex;
        width: 36px;
        height: 36px;
        justify-content: center;
        align-items: center;
        color: #fff;
        font-size: 18px;
      }
      a {
        color: #fff;
        &:active,
        &:visited {
          color: #fff;
        }
      }
    }
    li:nth-child(4n) {
      margin-right: 0;
    }
  }
}
</style>
